rm(list = ls())

library(fixest)
library(tidyverse)

## Load MP data

dat <- readRDS('data/mp_data.rds')  %>%
  filter(vote_abstain_no_show == 0) %>%
  filter(elecper == 8) %>%
  mutate(born_before_30 = ifelse(year_birth <= 1929, 'Before 1930', 'After 1930'))


m1 <- feols(vote_yes ~ nsdap_member + syn_in_gem_bin + veteran_ww1 + veteran_ww2 + capture_ww2 + soviet_capture + exile_repressed_combined + resistance_member + rel_cath + year_birth + gender + mandate + dualcand + closeness_district_categ | party_fe + state_id,
            data = dat,
            cluster = 'ags_cluster')

m2 <- feols(vote_yes ~ nsdap_member + syn_in_gem_bin + veteran_ww1 + veteran_ww2 + capture_ww2 + soviet_capture + exile_repressed_combined + resistance_member + rel_cath + year_birth + gender + mandate + dualcand + closeness_district_categ | party_fe + state_id,
            data = dat %>% filter(born_before_30 == 'After 1930'),
            cluster = 'ags_cluster')

m3 <- feols(vote_yes ~ nsdap_member + syn_in_gem_bin + veteran_ww1 + veteran_ww2 + capture_ww2 + soviet_capture + exile_repressed_combined + resistance_member + rel_cath + year_birth + gender + mandate + dualcand + closeness_district_categ | party_fe + state_id,
            data = dat %>% filter(born_before_30 == 'Before 1930'),
            cluster = 'ags_cluster')

m4 <- feols(vote_yes ~ nsdap_member + syn_in_loc_33_39 + veteran_ww1 + veteran_ww2 + capture_ww2 + soviet_capture + exile_repressed_combined + resistance_member + rel_cath + year_birth + gender + mandate + dualcand + closeness_district_categ | party_fe + state_id,
            data = dat %>% filter(born_before_30 == 'Before 1930'),
            cluster = 'ags_cluster_33_39') 


etable(list(m1, m2, m3, m4), 
       dict = c('syn_in_loc_33_39' = 'Synagogue: 1933-1939',
                'syn_in_gem_bin' = 'Synagogue: hometown',
                'vote_yes'= 'Vote for 1979 Statute of Lim. Extension',
                'party_fe' = 'Party',
                'state_id' = 'State',
                'born_before_30' = 'Year of birth'),
       digits = 4, 
       drop = c("Intercept", "Constant"),
       extralines = list('-Year of birth' = c('Full sample', 'after 1930', 'before 1930', 'before 1930'),
                         '-Covariates' = rep('Yes', 4)),
       keep = c('Synagogue'),
       title = '1979 Statute of limitations extension. The table shows results from OLS regressions where the outcome is a binary indicator that equals one for MPs who voted for the 1979 statute of limitations extension. The unit of observation are individual MPs. Standard errors are clustered by municipality/place of birth. ',
       adjustbox = .9,
       label = 'tab:1979_vote',
       digits.stats = 3,
       fitstat = ~ r2 + n,
       tex = T) 
